home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks96 / FlyPaper.sit / Fly Paper / FlyPaper Source / New Sources / ClippingWindow.cpp < prev    next >
Text File  |  1996-06-22  |  2KB  |  114 lines

  1. #ifndef CLIPPINGWINDOW_H
  2. #include "ClippingWindow.h"
  3. #endif
  4.  
  5. #ifndef CLIPPINGFILEDATA_H
  6. #include "ClippingFileData.h"
  7. #endif
  8.  
  9. #ifndef CLIPPINGFILE_H
  10. #include "ClippingFile.h"
  11. #endif
  12.  
  13. #ifndef FLOATERS_H
  14. #include "Floaters.h"
  15. #endif
  16.  
  17. #ifndef THUMBNAIL_H
  18. #include "Thumbnail.h"
  19. #endif
  20.  
  21. #define    kLeftWindowProc            3201        //    No drag bar
  22. #define    kRightWindowProc        3200        //    No drag bar
  23.  
  24. CClippingWindow::CClippingWindow (CClippingFile* theFile) :
  25.     fClippingFile (theFile),
  26.     fThumbnail (nil)
  27. {
  28.     CClippingFileData*        theData = theFile -> GetData ();
  29.     Boolean                    onLeft = theData -> GetOnLeft ();
  30.         
  31.     Rect                    bounds = CalculateWindowBounds (onLeft, theData -> GetOffset ());
  32.     fThumbnail = theFile -> GetThumbnail ();
  33.     if (!fThumbnail)
  34.         fThumbnail = CThumbnail::NewThumbnail (fClippingFile, bounds);
  35.         
  36.     fWindow = NewFloater (nil, &bounds, "\p", false,
  37.             onLeft ? kLeftWindowProc : kRightWindowProc, (WindowPtr) -1, false, (long) this, 0,
  38.             CClippingWindow::EventProc, CClippingWindow::ClippingDisposeProc);
  39.     if (!fWindow)
  40.         throw memFullErr;
  41.         
  42.     // ••• Reference the prefereces file for this information
  43.     Handle        wctb = GetResource ('wctb', 128 + (Random () & 0x7FFF) % 6);
  44.     if (wctb)
  45.         SetWinColor (fWindow, (WinCTab**)wctb);
  46.         
  47.     ShowWindow (fWindow);
  48.     UpdateFloater (fWindow);
  49. }
  50.  
  51. void CClippingWindow::ClippingDisposeProc (WindowPtr win)
  52. {
  53.     try {
  54.         delete ((CClippingWindow*) GetWRefCon (win));
  55.     } catch (...) {
  56.     }
  57. }
  58.  
  59. void CClippingWindow::EventProc (EventRecord *theEvent, WindowPtr win)
  60. {
  61.     CClippingWindow*    that = (CClippingWindow*) GetWRefCon (win);
  62.     if (!that)
  63.         return;
  64.         
  65.     try {
  66.  
  67.         switch (theEvent -> what) {
  68.         
  69.             case updateEvt :
  70.                 GrafPtr            oldPort;
  71.                 
  72.                 GetPort (&oldPort);
  73.                 SetPort (win);
  74.                 Rect    r = win -> portRect;
  75.                 InsetRect (&r, 6, 2);
  76.                 
  77.                 BeginUpdate (win);
  78.                 EraseRect (&win -> portRect);
  79.                 that -> fThumbnail -> Draw (r);
  80.                 EndUpdate (win);
  81.                 break;
  82.         }
  83.     } catch (...) {
  84.     }
  85. }
  86.  
  87. CClippingWindow::~CClippingWindow ()
  88. {
  89.     try {
  90.         DisposeFloater (fWindow);
  91.         delete fThumbnail;
  92.         delete fClippingFile;
  93.     } catch (...) {
  94.     }
  95. }
  96.  
  97. void CClippingWindow::RePositionWindow ()
  98. {
  99. }
  100.  
  101. Rect CClippingWindow::CalculateWindowBounds (Boolean onLeft, short offset)
  102. {    
  103.     Rect        screen = (**GetGrayRgn ()).rgnBBox;
  104.     Rect        bounds = { 0, 0, 20, 80 };
  105.     
  106.     if (onLeft) {
  107.         OffsetRect (&bounds, screen.left, offset);
  108.     } else {
  109.         OffsetRect (&bounds, screen.right - (bounds.right - bounds.left), offset);
  110.     }
  111.     
  112.     return bounds;
  113. }
  114.